package com

import org.apache.spark.SparkConf
import org.apache.spark.rdd.RDD
import org.apache.spark.streaming.{Seconds, StreamingContext}

import scala.collection.mutable

/**
 * 主要测试集群 处理能力测试的.
 */
object WordCount2 {
  def main(args: Array[String]): Unit = {
    // 从RDD队列中读取数据, 仅仅用于做压力测试
    val conf = new SparkConf().setMaster("local[2]").setAppName("WordCount2")
    val ssc = new StreamingContext(conf, Seconds(3))
    val rdds = mutable.Queue[RDD[Int]]()
    val sourceStream = ssc.queueStream(rdds, false)

    //求和
    val result = sourceStream.reduce(_ + _)

    result.print()
    ssc.start()

    val sc = ssc.sparkContext
    while (true) {
      // 往 rdd里面插入数据
      rdds.enqueue(sc.parallelize(1 to 100))
      Thread.sleep(100) //100毫秒处理一次.
    }

    ssc.awaitTermination()
  }
}
